#include "QtTileOffsetToEffect.h"
#include "QtPixmapSprite.h"

QtTileOffsetToEffect::QtTileOffsetToEffect(): target(0)
{
}

QtTileOffsetToEffect::~QtTileOffsetToEffect()
{
}

QtTileOffsetToEffect::QtTileOffsetToEffect(const QtTileOffsetToEffect& rhs): QtSingleAnimationEffect(rhs), target(rhs.target), endPosition(rhs.endPosition), startPosition(rhs.startPosition)
{

}

void QtTileOffsetToEffect::Update(qreal value)
{
	if (target)
	{	
		if (relative)
		{
			target->SetPixmapOffset( startPosition + endPosition*value );
		}
		else
		{
			target->SetPixmapOffset( startPosition + (endPosition-startPosition)*value );
		}
	}
}


void QtTileOffsetToEffect::SetTarget(QtPixmapSprite *sprite)
{
	target = sprite;
}

QtPixmapSprite* QtTileOffsetToEffect::Target() const
{
	return target;
}

void QtTileOffsetToEffect::SetRelativeEndPosition(const QPoint& position)
{
	endPosition = position;
	relative = true;
}

void QtTileOffsetToEffect::SetAbsoluteEndPosition(const QPoint& position)
{
	endPosition = position;
	relative = false;
}

void QtTileOffsetToEffect::SetupAnimation()
{
	if (target)
	{
		startPosition = target->PixmapOffset();
	}
}

QtAnimationEffect* QtTileOffsetToEffect::Clone() const
{
	return new QtTileOffsetToEffect(*this);
}

